package cn.jobstart.controller;

import cn.jobstart.dto.TalentSubscriptionTaskDTO;
import cn.jobstart.dto.TalentSubscriptionTaskPageDTO;
import cn.jobstart.enums.SysOperLogBusinessTypeEnum;
import cn.jobstart.enums.TalentSubscriptionTaskStatusEnum;
import cn.jobstart.export.TalentSubscriptionTaskDomainExport;
import cn.jobstart.modelExt.TalentSubscriptionTaskExt;
import cn.jobstart.pubInter.IBaseService;
import cn.jobstart.pubInter.aop.SystemLog;
import cn.jobstart.pubInter.exception.SkException;
import cn.jobstart.searchExt.TalentSubscriptionTaskSearchExt;
import cn.jobstart.service.ITalentSubscriptionTaskService;
import cn.jobstart.vo.TalentSubscriptionTaskDetailDomainVO;
import cn.jobstart.vo.TalentSubscriptionTaskDetailVO;
import cn.jobstart.vo.TalentSubscriptionTaskDomainVO;
import cn.jobstart.vo.TalentSubscriptionTaskListVO;
import cn.jobstart.web.common.SkJsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashSet;
import java.util.Set;

/**
 * @author sunke
 * @Date 2023-09-06 15:00:21
 * @description TalentSubscriptionTaskController      人才订阅任务
 */
@Api(tags = "人才管理系统-人才订阅任务相关", description = "人才订阅任务相关接口")
@RestController(value = "talentSubscriptionTaskRestfulController")
@RequestMapping("/talentSubscriptionTask/")
@Validated
public class TalentSubscriptionTaskController extends ApiManageController<TalentSubscriptionTaskDTO, TalentSubscriptionTaskPageDTO, TalentSubscriptionTaskExt, TalentSubscriptionTaskSearchExt, TalentSubscriptionTaskDomainVO, TalentSubscriptionTaskDetailDomainVO, TalentSubscriptionTaskDetailVO, TalentSubscriptionTaskListVO, String> {

    @Resource(name = "talentSubscriptionTaskService")
    private ITalentSubscriptionTaskService talentSubscriptionTaskService;


    @ApiOperation(value = "启动某一订阅", notes = "启动某一订阅", httpMethod = "POST")
    @PostMapping("startAction/{id}")
    @SystemLog(title = "启动某一订阅", businessType = SysOperLogBusinessTypeEnum.GRANT_TYPE, method = "startAction")
    public SkJsonResult startAction(@PathVariable String id, HttpServletRequest request, HttpSession session) throws SkException {
        talentSubscriptionTaskService.start(id, getJwtsUtil().getAdminId(request), getJwtsUtil().getAdminTruename(request));
        return SkJsonResult.ok();
    }

    @ApiOperation(value = "暂停某一订阅", notes = "暂停某一订阅", httpMethod = "POST")
    @PostMapping("stopAction/{id}")
    @SystemLog(title = "暂停某一订阅", businessType = SysOperLogBusinessTypeEnum.GRANT_TYPE, method = "stopAction")
    public SkJsonResult stopAction(@PathVariable String id, HttpServletRequest request, HttpSession session) throws SkException {
        talentSubscriptionTaskService.stop(id, getJwtsUtil().getAdminId(request), getJwtsUtil().getAdminTruename(request));
        return SkJsonResult.ok();
    }




    @Override
    public boolean beforePostAdd(TalentSubscriptionTaskDTO dto, TalentSubscriptionTaskExt domain, HttpServletRequest request, HttpSession session) throws SkException {

        String adminId = getJwtsUtil().getAdminId(request);

      /*  if (!adminService.canSubscriptionByAdminId(adminId)) {
            throw new BusinessException(ExceptionMessage.ADMIN_SUBSCRIPTION_MAX_ERROR);
        }*/

        domain.setAdminId(adminId);
        domain.setAdminTruename(getJwtsUtil().getAdminTruename(request));
        domain.setStatus(TalentSubscriptionTaskStatusEnum.CREATE.getType());
        domain.setResumeCount(0);
        domain.setResumeGraspCount(0);
        domain.setResumeUpdateCount(0);
        return super.beforePostAdd(dto, domain, request, session);
    }


    @Override
    public IBaseService<TalentSubscriptionTaskExt, TalentSubscriptionTaskSearchExt, String> getBaseService() throws SkException {
        return talentSubscriptionTaskService;
    }

    @Override
    public String getBaseRoute() {
        return "/talentSubscriptionTask/";
    }

    /**
     * 当前模板名称
     *
     * @return
     */
    @Override
    public String getModelName() {
        return "人才订阅任务";
    }

    @Override
    public Class exportExcelClass() {
        return TalentSubscriptionTaskDomainExport.class;
    }

    @Override
    public Set<String> totalMapSet() {
        Set totalMapSet = new HashSet();
        totalMapSet.add("count(talent_subscription_task.tst_id) as countNum");
        return totalMapSet;
    }


}